#ifndef PIPELINE_H
#define PIPELINE_H

#include <pthread.h>
#include <stdbool.h>
#include "v4l2.h"
#include "drm_device.h"
#include "rknn_engine.h"
#include "rga_util.h" // Include the new RGA utility header

#define BUFFER_QUEUE_SIZE (4)
// buffer_queue_t 不再需要，可以删除相关的前向声明和定义
typedef struct
{
    // 将 capture_tid 改名为 inference_tid，更符合其功能
    pthread_t inference_tid; 
    pthread_t display_tid;
    // 移除 queue
    // buffer_queue_t *queue;
    // 新增用于线程同步的互斥锁和条件变量
    pthread_mutex_t display_mutex;
    pthread_cond_t  display_cond;
    volatile int    latest_idx;  // 最新的、已处理完的buffer索引
    volatile int    display_idx; // 正在显示的buffer索引
    v4l2_context_t *v4l2;
    drm_device_t   *drm;
    rknn_engine_context_t *rknn;
    rga_context_t *rga;
    volatile bool  *quit_flag;
} pipeline_context_t;


int pipeline_init(pipeline_context_t *ctx, v4l2_context_t *v4l2_ctx, drm_device_t *drm_ctx,
                  rknn_engine_context_t *rknn_ctx, rga_context_t *rga_ctx, volatile bool *quit_flag);
int pipeline_start(pipeline_context_t *ctx);
void pipeline_stop(pipeline_context_t *ctx);
void pipeline_cleanup(pipeline_context_t *ctx);

#endif // PIPELINE_H
